package com.xhf.tools;


import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONWriter;
import com.xhf.tools.entity.Animal;
import com.xhf.tools.entity.Cat;
import com.xhf.tools.entity.JsonDataEntity;

import java.util.ArrayList;
import java.util.List;

public class JsonUtil {

    public static JSONObject parseObjec(String json) {
        JSONObject jsonObject = JSON.parseObject(json);
        return jsonObject;
    }

    public static void main(String[] args) {
        Animal cat = new Cat("cat1",2);
        Animal cat2 = new Cat("cat2",2);
        List<Animal> animalList = new ArrayList<>();
        animalList.add(cat);
        animalList.add(cat2);
        JsonDataEntity jsonDataEntity = new JsonDataEntity();
        jsonDataEntity.setAnimalList(animalList);

        String json = JSON.toJSONString(new JsonDataEntity(), JSONWriter.Feature.LargeObject
                ,JSONWriter.Feature.FieldBased,JSONWriter.Feature.IgnoreNonFieldGetter);

        System.out.println(json);

    }

}
